Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

[RESOLVED] WCF service in local IIS and run with Jquery.

$
0
0
Hi.
Is that so hard? Do i need cross domain stuff???
I am creating a simple WCF and i want to call it from local IIS. I cannot do it, whatever i try.
The service will work if i have it inside a web site but not stand alone.
Here is the data:
Code:

''Service:
Imports System.ServiceModel.Activation
Imports System.Web.Script.Serialization

' NOTE: You can use the "Rename" command on the context menu to change the class name "VSAPIAJAX" in code, svc and config file together.
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class VSAPIAJAX
    Implements IVSAPIAJAX

    Public Sub DoWork() Implements IVSAPIAJAX.DoWork
    End Sub

    Function test() As String Implements IVSAPIAJAX.test
        Return "g"
    End Function
End Class

Code:

interface:
Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports System.Runtime.Serialization

' NOTE: You can use the "Rename" command on the context menu to change the interface name "IVSAPIAJAX" in both code and config file together.
<ServiceContract()>
Public Interface IVSAPIAJAX

    <OperationContract()>
    Sub DoWork()

    <WebInvoke(Method:="POST", ResponseFormat:=WebMessageFormat.Json)> _
    <OperationContract()> _
    Function test() As String


End Interface

Code:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ServiceAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>     
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>             
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>     
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="VSAPIAJAX">
        <endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior"
          binding="webHttpBinding" contract="IVSAPIAJAX">
          <!--  <identity>
            <dns value="localhost" />
          </identity> -->
        </endpoint>       
      </service>       
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
 
</configuration>

Code:

//Javascript

<script src="Javascript/jquery-1.11.2.min.js" type="text/javascript"></script>
 <script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "http://localhost:15328/VSAPIAJAX.svc/test",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                alert('d');
                try {
                    var oRetVal = response.d;
                    alert(d);
                }
                catch (ex) {
                    alert(ex);
                }
            },
            failure: function (msg) {
                alert(msg);
            }
        });
        alert('error');
    });
    </script>

Have tried local iis and local website asp server.Cannot get anything. Is this so hard to call a WCF service outside a web site?
Thanks

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>