通过 Windows Phone 7 使用 Web 服务并添加 SOAP 标头

发布于 2025-01-04 11:14:55 字数 1534 浏览 1 评论 0原文

我有一个 webservice 方法,描述如下:

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 应用程序中却不能。

有人对这个问题有建议吗?谢谢现在。

I have a webservice method which described as follow:

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>

And i'm trying develop a Windows Phone 7 application which consumes this webservice method. In Visual Studio, i added the service referance to my project. I created Webservice client object like as doing it in .net platform, and created AuthHeader object and set its username and password. The following code is not my code but it like as mine:

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

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

But when i trying to set services headers with using this code line:

webService.AuthHeaderValue = authentication;

it doesn't work. webservice object doesn't have AuthHeaderValue property. I tried it in desktop application or a web application it works but in Windows Phone 7 application it did not.

Does anybody have a suggestion about this issue? Thanks for now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙味迷妹 2025-01-11 11:14:55

这是我朋友针对这个问题的解决方案,它对我有用:

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 服务

This is my friend's solution for this problem and it is work for me:

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;
}

And the full blog post is here: WP7 SOAP Web Service with Custom Headers

就此别过 2025-01-11 11:14:55

当我尝试与 SOAP 服务通信时,我遇到了类似的问题。我猜问题是WP7中Silverlight的版本问题。
您是否尝试过在 Windows 窗体项目中引用 Web 服务?就我而言,在 Windows 窗体项目中添加 SOAP Web 服务没有问题,但当我将其添加到 WP7 项目时,并非 SOAP 服务的所有属性和方法都可用。
最后我不得不编写自己的 SOPA Webservice 类来与服务器通信。

I had a similar problem when I was trying to communicate with a SOAP service. I guess the problem is the version of the Silverlight in WP7.
Have you tried to reference the webservice in a Windows Form project? In my case it was no problem to add my SOAP webservice in a Windows Form project but when I added it to a WP7 project not all properties and methods of the SOAP service were available.
In the end I had to write my own SOPA Webservice class to communicate with the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文