2014-09-10 46 views
0

我有一个SOAP WebService,它具有授权,并要求我将ClientCredentialType指定为HttpClientCredentialType.Basic。Windows Phone Silverlight 8.0 - 在BasicHttpBinding上将ClientCredentialType指定为Basic

我正常的.NET项目,我可以指定这个(在代码或XML)连接到我的WebService:

BasicHttpBinding binding = new BasicHttpBinding(); 
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
mySoapClient = new MySoapClient(binding, address); 

的问题是,在便携式类库(PCL),或在Windows Phone 8.0 Silverlight C#项目属性Transport不存在。

是否有解决方法?

谢谢

回答

0

找出答案。 看起来像所有的请求必须在OperationContextScope中执行。

 private void InvokeWebMethod(Action webMethod, string username = null, string password = null) 
     { 
      using (OperationContextScope contextScope = new OperationContextScope(presenceServer.InnerChannel)) 
      { 
       var bc = Encoding.UTF8.GetBytes(string.Format(@"{0}:{1}", username ?? this.Username, password ?? this.Password)); 
       HttpRequestMessageProperty httpProps = new HttpRequestMessageProperty(); 
       httpProps.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(bc); 

       OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpProps; 
       webMethod(); 
      } 
     } 

THanks。

相关问题