关于从我的 Windows Phone 应用程序通过 RestSharp 发送到我创建的自托管 WCF 服务的休息请求,我遇到了一些麻烦。该请求在模拟器中运行良好,并且请求返回结果,但是当我尝试在实际设备上的应用程序上执行请求时,它失败并且请求不返回任何内容。
经过大量研究后,我发现 Windows Phone 显然不支持 webHttpBinding,因此我需要在我的Web.config文件中添加一个basicHttpBinding端点。但是,当我尝试这样做时,我遇到了与拥有多个端点相关的几个错误,而且我似乎无法找到任何解决方案来成功使用这两个端点。当我导航到 localhost:81/mywebservice.svc 时,将端点切换到 basicHttpBinding 并注释掉 webHttpBinding 也会导致错误
"System.InvalidOperationException: For request in operation analyseFace to be a stream the operation must have a single parameter whose type is Stream."
请求应附加请求的流。它显示了一个使用原始代码和相同地址的普通帮助页面。
我的 web.config 文件
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<behavior name="servicebehavior">
<!--<serviceMetadata httpGetEnabled="true"/>-->
<serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restbehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="servicebehavior" name="VizageAPIWebRole.vizage">
<endpoint address="" behaviorConfiguration="restbehavior" binding="webHttpBinding" name="RESTEndPoint" contract="VizageAPIWebRole.Ivizage" />
<!--<endpoint address="" binding="basicHttpBinding" contract="VizageAPIWebRole.Ivizage" />-->
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="RestBinding">
<readerQuotas maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" />
<security mode="None">
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
我的 WCF 服务
[ServiceContract]
public interface Ivizage
{
[WebInvoke(UriTemplate = "/agerecog/{auth}", Method = "POST")]
VizageResult analyseFace(string auth, Stream dataStream);
}
我想知道是否有人可以帮助我确定我必须在 web.config 中编辑哪些代码才能使这对两个端点都有效,因为到目前为止我尝试过的事情都没有运气