Gumbo
Gumbo

Reputation: 201

How can I call my WCF service from browser?

I'm writing a webservice that is suppose to save json two json strings to DB. I can invoke it with sope UI and WCF Test Client but I can't call it from my browser. Is there some way to do that?

The service will initially be used by android app and I have tried calling from it with out any luck.

Here is the interface of my service:

 [ServiceContract]
public interface IRService
{
    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
       BodyStyle = WebMessageBodyStyle.Wrapped,
       UriTemplate = "SaveCallResults?callInfo={callInfo}&testInfo={testInfo}")]
    string SaveCallResults(string callInfo, string testInfo);
}

And here is my web.config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_RService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false"            hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536"
      textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
      messageEncoding="Text">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"
  multipleSiteBindingsEnabled="true" />
<services>
  <!-- causing error -->
  <!--<service name="NovaRoadRunnerWS.RService" behaviorConfiguration="ServiceBehaviour" >
    <endpoint address="" binding="webHttpBinding" contract="NovaRoadRunnerWS.IRService" behaviorConfiguration="web" >
    </endpoint>
  </service>-->
</services>

Upvotes: 5

Views: 7919

Answers (1)

Syed Raihan
Syed Raihan

Reputation: 126

There are several errors in the web.config:

  1. There is no service behavior named ServiceBehaviour behaviorConfiguration="ServiceBehaviour"

  2. There is no endpoint behavior named web: behaviorConfiguration="web"

  3. No name was given to the serviceBehaviors section: <behavior name="">

I made the following change to fix the error:

<behaviors>
  <serviceBehaviors>
    <behavior name="web">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

and

<services>
  <service name="NovaRoadRunnerWS.RService" behaviorConfiguration="web" >
    <endpoint address="" binding="webHttpBinding" contract="NovaRoadRunnerWS.IRService"  >
    </endpoint>
  </service>
</services>

Upvotes: 9

Related Questions