无法使用C#使用Web服务,但在邮递员上工作

问题描述

我正在尝试通过httpwebrequest调用网络服务。成功添加XML文档和标头,但仍然出现错误内部服务器错误500 。从调试模式复制的相同xml文档在邮递员上正常工作。我的代码

2020-09-16T11:23:54.292896+00:00 app[web.1]: 9/16/2020 11:23:54 23 [ERROR] Node Media Trans Server startup Failed. ffmpeg:/vendor/ffmpeg cannot be executed.

我还尝试绕过ssl证书,因为web服务服务器ssl证书已过期或不受信任。请帮忙,因为我被卡住了。我也尝试过WSDL文件,但同样不能成功。

修改 在这里,我添加的图像是我在邮递员中尝试过 webservice 的方式

enter image description here

enter image description here

解决方法

已解决

经过非常艰难的发现,我以某种方式知道,如果webservice在邮递员上成功运行,它还会提供该语言的代码(就在“保存”按钮下方)。因此,我使用了该代码(基于 RestClient )。 我的错误是没有在XML文档中使用\ r \ n和适当的空格所以xml是问题所在。

//THis code used for ssl bypassing
ServicePointManager
                .ServerCertificateValidationCallback +=
            (sender,cert,chain,sslPolicyErrors) => true;


        var client = new RestSharp.RestClient(webservice_url)
        {
            Timeout = -1
        };
        var request = new RestSharp.RestRequest(Method.POST);
        request.AddHeader("Content-Type","text/xml");
        request.AddHeader("SOAPAction","action");
        request.AddParameter("text/xml","<soapenv:Envelope xmlns:soapenv=\"url1" xmlns:hhm=\"url2">\r\n\t<soapenv:Header>\r\n\t\t<UsernameToken>username</UsernameToken>\r\n\t\t<PasswordText>password</PasswordText>\r\n\t\t<SessionType>None</SessionType>\r\n\t</soapenv:Header>\r\n   <soapenv:Body>\r\n      <hhm:CreateFollowup_Input>\r\n         <hhm:FollowupAction>testing</hhm:FollowupAction>\r\n         <hhm:CloseOutSubReason></hhm:CloseOutSubReason>\r\n         <hhm:FolloUpStatus>Open</hhm:FolloUpStatus>\r\n         <hhm:Object_spcId>1-3B39WBFE</hhm:Object_spcId>\r\n         <hhm:Model></hhm:Model>\r\n         <hhm:CloseReason></hhm:CloseReason>\r\n         <hhm:FollowUpDate>08/20/2020</hhm:FollowUpDate>\r\n         <hhm:ExpectedPurchaseDate></hhm:ExpectedPurchaseDate>\r\n         <hhm:FollowUpQuestions></hhm:FollowUpQuestions>\r\n         <hhm:FollowUpDone></hhm:FollowUpDone>\r\n         <hhm:DSEName>10086S20</hhm:DSEName>\r\n         <hhm:MakeBought></hhm:MakeBought>\r\n      </hhm:CreateFollowup_Input>\r\n   </soapenv:Body>\r\n</soapenv:Envelope>",ParameterType.RequestBody);
        RestSharp.IRestResponse response = client.Execute(request);
        Console.WriteLine(response.Content);
        return response.Content.ToString();