Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

Consume WCF from Android

I have an WCF API that is working on IIS when called by a Windows application using web SeviceReference. I am not trying to get it work when called by an Android application. I would assume I could "test" the otherwise working API from a web browser, or from Fiddler, to make sure my calling syntax was correct, but when I try, I get a 404 error.

My Webservice Web.config serviceModel is as follows:

 <system.serviceModel>
<protocolMapping>
  <add scheme="http" binding="basicHttpBinding"/>
</protocolMapping>

<services>
  <service name="TaskTrackerAppService.Service1" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="basicHttpBinding"  contract="TaskTrackerAppService.IAppWebService"></endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" bindingConfiguration=""></endpoint>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>

  </basicHttpBinding>
</bindings>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

When I enter into a browser:

http://localhost:51276/AppWebService.svc and 
http://localhost:51276/AppWebService.svc?wsdl

I do get the expected WSDL response. (From both my localhost and from the hosted web server where this WCF has been running.)

So next I add in the request for:

 http://localhost:51276/AppWebService.svc/SayHello/1000

Where SayHello will return confirmation that userId 1000 exists. And I get back:

404 - The resource cannot be found

I've also tried:

http://localhost:51276/AppWebService.svc/SayHello?userId=1000 etc.

Help. I'm stuck. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have an endpoint configuration for

<endpointBehaviors>
    <behavior name="webBehavior">
        <webHttp />
    </behavior>
</endpointBehaviors>

but none of your endpoints use it.

Pick an endpoint and use this behavior. Right now, it's dead, unused XML.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...