2017-11-03 17 views
0

:형식 SOAP 메시지, 이것은 그가 기대하고 제가 SOAP 1.1 메시지와 Webservice를 우리의 고객이 요구하는 형식의 문제에 봉착입니다

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" > 
    <SOAP-ENV:Body > 
     <m:PingResponse xmlns:m="http://www.mycompany.com/service" Token="E30ED3AA-65DE-48F9-BEA4-BA021B119625" Echo="Hello!" Status="Successful" /> 
    </SOAP-ENV:Body > 
</SOAP-ENV:Envelope > 

을 그리고 이것은 내가 가진 무엇 지금

<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"> 
    <soap:Body> 
     <PingRequestResponse xmlns="http://www.mycompany.com/service"> 
      <m:PingResponse Token="E30ED3AA-65DE-48F9-BEA4-BA021B119625" Status="Success" xmlns:m="http://www.mycompany.com/service" /> 
     </PingRequestResponse> 
    </soap:Body> 
</soap:Envelope> 

때까지 난 당신이 내 대답에 볼 수

[WebService(Namespace = "http://www.mycompany.com/service")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
public class MyService : System.Web.Services.WebService 
{ 
    [WebMethod] 
    public PingResponse PingRequest([XmlAttribute] string Token) 
    { 
     //do stuffs 
     if (success) { 
      return new PingResponse { Token = Token, Status = "Success" }; 
     } 
     else { 
      return new PingResponse { Token = Token, Status = "Failed", Error = new Error { Code = "NoConnection", Message = "Can't reach the server" } }; 
     } 
    } 
} 

[XmlRoot(ElementName = "PingResponse", Namespace = "http://www.mycompany.com/service")] 
public class PingResponse 
{ 
    [XmlNamespaceDeclarations] 
    public XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces(); 

    [XmlAttribute] 
    public string Token { get; set; } 
    [XmlAttribute] 
    public string Status { get; set; } 
    [XmlElement(ElementName = "Error", Namespace = "http://www.mycompany.com/service")] 
    public Error Error { get; set; } 

    public PingResponse() 
    { 
     xmlns.Add("m", "http://www.mycompany.com/service"); 
    } 
} 

[DataContract(Namespace = "http://www.mycompany.com/service")] 
public class Error 
{ 
    [XmlAttribute] 
    public string Code { get; set; } 
    [XmlAttribute] 
    public string Message { get; set; } 
} 

그래서 구현하는 광고입니다있어 어떻게 itional XML 요소는 PingRequestResponse 이전 또한 내가 = "PingResponse"ElementName을합니다 ([XmlRoot으로 제거 할 수 있지만, 상기 PingRequestResponse 아래 PingRequestResult 불리는 다른 요소였다 한 상기 MethodNameResponse 포맷 WebService에 의해 발생이라고 내 수업 시간에

그래서 나는 다음 수행해야합니다

  • 제거 PingRequestResponse 요소를 직접 몸 아래 PingResponse을 넣어
  • 변경 SOAP 메시지에 대한 네임 스페이스 (봉투 및 바디) "SOAP-ENV는"
  • 이 어떤 도움을 이해할 수있을 것이다 SOAP 메시지

에서 XSI 및 XSD를 제거하는, 감사합니다.

편집 : 지금까지

내가 WSDL을하지 않은, 그래서 이것은 XML 네임 스페이스를 추가하는 인터넷 라이브러리 싸우고 과거의 시간을 지금

+0

WSDL을 요청하고 하향식 방식을 사용하십시오. – Namphibian

+0

그래, 이미 며칠 전에 WSDL을 요청했다. 그러나 지금까지는 – Heybrajham

답변

0

내가 지출 한 많은에 대한 옵션이 아닙니다. 다른 메소드가 작동하지 않으면 필요한 문자열을 간단히 구문 분석합니다. 훨씬 더 청결한

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml; 
using System.Xml.Linq; 


namespace ConsoleApplication13 
{ 
    class Program 
    { 

     static void Main(string[] args) 
     { 
      string xmlStr = 
       "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" >" + 
        "<SOAP-ENV:Body >" + 
         "<m:PingResponse xmlns:m=\"http://www.derbysoft.com/chapaai\" />" + 
        "</SOAP-ENV:Body >" + 
       "</SOAP-ENV:Envelope >"; 

      XElement envelope = XElement.Parse(xmlStr); 
      XElement response = envelope.Descendants().Where(x => x.Name.LocalName == "PingResponse").FirstOrDefault(); 

      response.Add(new XAttribute("Token", "E30ED3AA-65DE-48F9-BEA4-BA021B119625")); 
      response.Add(new XAttribute("Echo", "Hello")); 
      response.Add(new XAttribute("Status", "Successful")); 
     } 

    } 

}