C# 在WP8应用程序中调用RP下的Rest WCF服务
我正在尝试调用处于反向代理下的REST Web服务。 我确信登录名、域和密码是正确的 我使用HTTPClient可移植库C# 在WP8应用程序中调用RP下的Rest WCF服务,c#,web-services,wcf,rest,windows-phone-8,C#,Web Services,Wcf,Rest,Windows Phone 8,我正在尝试调用处于反向代理下的REST Web服务。 我确信登录名、域和密码是正确的 我使用HTTPClient可移植库 private async void bt1_Click(object sender, RoutedEventArgs e) { var c = new NetworkCredential() { Domain = "XXXXX", UserName = "XXXX.XXXX",
private async void bt1_Click(object sender, RoutedEventArgs e)
{
var c = new NetworkCredential()
{
Domain = "XXXXX",
UserName = "XXXX.XXXX",
Password = "XXXXXXX"
};
HttpClientHandler h = new HttpClientHandler();
h.Credentials = c;
HttpClient cl = new HttpClient(h);
HttpResponseMessage response = await cl.GetAsync("https://XXXXXXXXX.fr/XXXXXXX.svc/getdepartcollection");
}
也许我犯了一个错误,或者也许有另一种方法叫服务。我有一个结果:
{StatusCode:401,ReasonPhase:'需要授权',版本:0.0,内容:System.Net.Http.StreamContent,标题:
{
日期:2014年7月1日星期二09:30:03 GMT
WWW-Authenticate:Basic realm=“XXXXXX”
设置Cookie:bwfsessidmhcqaf7yddn5kzq7jjef72v5h2=xehlsv8hlmpbh75z3u897ug6muchyl5b7asyu77aqd5n95c3xrpx6ph27nlc2bs5gmfyqhrzhs882bkwvfcq49m79axrasgpcv9lxum6nqarm55sxtrm9pwsw6wladd82fe8v2br2bcuccuc6jfg9fnjfjf9t4f4f3rx4f3rzzbhzbhzhzhhg8wzzzzzwq8w8bjjjjjjjjjjd8wq4hzzjjjjjjjjjjjjjjjjjjjjjjjzzzzzzzzzzzzzzzzzzz
缓存控制:最大年龄=0,专用
Pragma:没有缓存
改变:接受编码
保持活动状态:超时=5,最大=299
连接:保持活力
内容长度:401
内容类型:text/html;字符集=iso-8859-1
}}
编辑:我遵循此链接,但它也不起作用:
这是我的web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint crossDomainScriptAccessEnabled="true"/>
</webScriptEndpoint>
</standardEndpoints>
<services>
<service name="XXXXXXXXXXXXXX.XXXXXXXXXXXXXXX" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web"
contract="XXXXXXXXXXX.XXXXXXXXXXXXXX"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="CopySoap" 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="655360" maxReceivedMessageSize="655360"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
messageEncoding="Text">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"
realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://XXXXXXXXXXXXXXXXXXXXXXXXXX.fr/_vti_bin/copy.asmx"
binding="basicHttpBinding" bindingConfiguration="CopySoap"
contract="SP.CopySoap" name="CopySoap" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
您确定在您的R WCF Rest服务中实施了跨域策略吗?我创建了一个clientaccessprolicy和一个跨域策略,但它没有改变任何内容。