2013-05-13 46 views
0

我對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> 
+0

我沒有看到任何實際的Web服務調用,你從哪裏得到你的迴應? – Hanno 2013-05-14 07:27:43

+0

嗨Hanno,請求和響應包含在文檔中。我想弄清楚如何讓我的第一個電話。 – user2379544 2013-05-14 12:28:38

回答

0

它看起來像BriefDescription不是字符串類型。嘗試是這樣的:

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

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

(對不起,我不知道是什麼屬性 「StringType」 實際上有)。

+0

嗨Appclay,謝謝你的迴應。我想你這兩個例子provided.Error 「SM9.ServiceReference1.StringType」不包含一個構造函數1個參數\t 錯誤無法隱式轉換類型「SM9.ServiceReference1.StringType」到「字符串」 – user2379544 2013-05-14 12:31:10

+0

的錯誤告訴你,你正試圖將類型爲「SM9.ServiceReference1.StringType」的東西設置爲「string」類型的東西。我只是用我的答案猜測,因爲我沒有你的代碼來測試它。 – joshuahealy 2013-05-15 05:31:14