【问题标题】:Creating my first soap request创建我的第一个肥皂请求
【发布时间】:2013-05-13 22:52:43
【问题描述】:

我对 Web 服务/api 调用相当陌生

我获得了一个用于开发的 wsdl。

http://bogus.com/SM/7/ServiceCatalogAPI.wsdl

我使用 Visual Studio 2010 c# .net 4.0 添加了对 wsdl 的服务引用

我已获得用户名/密码(基本身份验证)

我正在寻找有关如何执行请求的指导。我走对了吗?

我有以下内容,但我收到“无法将类型“字符串”隐式转换为“SM9.ServiceReference1.StringType”

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        ServiceReference1.CreateCartRequest createCart = new ServiceReference1.CreateCartRequest();

        string result = createCart.model.instance.BriefDescription = "Testing SM9";

        Label1.Text = result.ToString();
    }
    catch (System.Exception ex)
    {
        Label1.Text = ex.Message;
    }
}

SOAP 请求

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:ns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common">
  <soap:Body>
    <ns:CreateCartRequest>
      <ns:model>
        <ns:keys/>
        <ns:instance>
          <ns:BriefDescription type="">Brief Description</ns:BriefDescription>
          <ns:Description type="">
            <ns:Description type="">description 1</ns:Description>
            <ns:Description type="">description 2</ns:Description>
          </ns:Description>
        </ns:instance>
      </ns:model>
    </ns:CreateCartRequest>
  </soap:Body>
</soap:Envelope>

SOAP 响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>
    <CreateCartResponse message="Success" returnCode="0" schemaRevisionDate="2012-09-12" schemaRevisionLevel="0" status="SUCCESS" xmlns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.hp.com/SM/7 http://SE104636.devfg.RBC.com:12700/SM/7/Cart.xsd">
      <model>
        <keys>
          <CartID type="Decimal">11</CartID>
        </keys>
        <instance recordid="11" uniquequery="cartId=11">
          <CartID type="Decimal">11</CartID>
          <Completed type="Boolean">false</Completed>
          <BriefDescription type="String">Brief Description</BriefDescription>
          <Owner type="String">SOAP USER</Owner>
          <Description type="Array">
            <Description type="String">description 1</Description>
            <Description type="String">description 2</Description>
          </Description>
          <Cost type="Decimal">0</Cost>
        </instance>
      </model>
      <messages>
        <cmn:message>svcCart record added.</cmn:message>
      </messages>
    </CreateCartResponse>
  </SOAP-ENV:Body>

【问题讨论】:

  • 我没有看到对网络服务的任何实际调用,您从哪里得到响应?
  • 您好 Hanno,请求和响应已包含在文档中。我正在尝试弄清楚如何拨打我的第一个电话。

标签: c# .net web-services soap


【解决方案1】:

看起来BriefDescription 不是字符串类型。试试这样的:

string result = createCart.model.instance.BriefDescription = new StringType("Testing SM9");

 string result = createCart.model.instance.BriefDescription = new StringType() { Value = "Testing SM9" };

(对不起,我不知道“StringType”实际上有什么属性)。

【讨论】:

  • 您好 Appclay,感谢您的回复。我尝试了您提供的两个示例。错误 1 ​​'SM9.ServiceReference1.StringType' 不包含带有 1 个参数的构造函数错误 1 ​​无法将类型 'SM9.ServiceReference1.StringType' 隐式转换为 'string'
  • 错误告诉您您正在尝试将“SM9.ServiceReference1.StringType”类型的内容设置为“字符串”类型的内容。我只是猜测我的答案,因为我没有你的代码来测试它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
  • 2020-07-29
相关资源
最近更新 更多