2012-02-10 88 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类来与服务器进行通信。