2012-02-10 86 views
1

我有描述如下web服務方法:與Windows Phone 7和添加SOAP頭消費的WebServices

POST /servis.asmx HTTP/1.1 
Host: webservice.myproject.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://tempuri.org/MyMethod" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
       xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
    <AuthHeader xmlns="http://tempuri.org/"> 
     <Username>string</Username> 
     <Password>string</Password> 
    </AuthHeader> 
    </soap:Header> 
    <soap:Body> 
    <MyMethod xmlns="http://tempuri.org/" /> 
    </soap:Body> 
</soap:Envelope> 

我試圖開發一種消耗此WebService方法在Windows Phone 7應用程序。在Visual Studio中,我將服務參考添加到了我的項目中。我在.net平臺上創建了Webservice客戶端對象,並創建了AuthHeader對象並設置其用戶名和密碼。下面的代碼是不是我的代碼,但它像礦山:

 AuthWebService.WebService webService = new AuthWebService.WebService(); 
     AuthWebService.AuthHeader authentication = new AuthWebService.AuthHeader(); 

     authentication.Username = "test"; 
     authentication.Password = "test"; 
     webService.AuthHeaderValue = authentication; 

但是,當我試圖設置服務與頭使用此代碼行:

webService.AuthHeaderValue = authentication; 

這是行不通的。 webservice對象沒有AuthHeaderValue屬性。我嘗試過在桌面應用程序或Web應用程序中運行,但在Windows Phone 7應用程序中沒有。

有沒有人有關於這個問題的建議?現在感謝。

回答

1

這是我的朋友對這個問題的解決方案,這是對我工作:

public class _ServiceCredential 
{ 
    [XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.None)] [DataMember(Order = 2)] 
    public string Password; 
    [DataMember(Order = 1)] 
    [XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.None)] 
    public string Username; 
} 

並全面博客文章是在這裏:WP7 SOAP Web Service with Custom Headers

0

我在嘗試與SOAP服務進行通信時遇到了類似的問題。我猜這個問題是WP7中的Silverlight版本。 您是否嘗試過在Windows窗體項目中引用Web服務?在我的情況下,將我的SOAP webservice添加到Windows窗體項目中是沒有問題的,但是當我將它添加到WP7項目時,並不是SOAP服務的所有屬性和方法都可用。最後,我不得不編寫自己的SOPA Webservice類來與服務器進行通信。