You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#中如何使用Web不可访问的WSDL/XSD实现SOAP服务?

Hey there! Let's break this down step by step to get you sorted with your SOAP service in Visual Studio.

1. First: Confirm if your service reference was generated correctly

It's totally normal that you don't see a visible .cs file right away—Visual Studio hides the auto-generated code by default. Here's how to verify everything worked:

  • In Solution Explorer, toggle the Show All Files button (top of the explorer pane).
  • Expand your ePayments service reference, then expand the Reference.svcmap folder. You'll find the generated .cs file there (usually named Reference.cs).
  • Alternatively, open the Object Browser (View → Object Browser), navigate to the ePayments namespace, and check for these key types:
    • rmt_wsClient: The main client class to call the service
    • remittanceXml: The request type
    • remittanceXmlResponse: The response type
    • UnsupportedEncodingException: The fault exception type

If all these exist, your service reference was generated correctly!

2. How to use the generated client to call the SOAP service

Once you've confirmed the types are there, here's a concrete example of how to send a request matching the SOAP sample you provided:

using (var client = new ePayments.rmt_wsClient())
{
    // Build your input XML (match the structure from your SOAP sample)
    string inputXml = @"<remittance>
        <wsTin>Tin</wsTin>
        <wsUser>Username</wsUser>
        <wsPswd>Pswd</wsPswd>
        <contain>
            <bmrn>16GRIMXXXX00001746</bmrn>
            <blrn>TESTFOR1</blrn>
            <bcnt>1</bcnt>
            <bafm>099099099</bafm>
        </contain>
        <contain>
            <bmrn>16GRIMXXXX00001720</bmrn>
            <blrn>TESTFOR2</blrn>
            <bcnt>2</bcnt>
            <bafm>099099099</bafm>
        </contain>
    </remittance>";

    try
    {
        // Call the service method
        var response = client.remittanceXml(inputXml);
        
        // Access the returned XML from the response
        string resultXml = response.@return;
        Console.WriteLine("Service response: " + resultXml);
    }
    catch (ePayments.UnsupportedEncodingExceptionFault ex)
    {
        // Handle the specific fault from the service
        Console.WriteLine("Encoding error: " + ex.Message);
    }
    catch (Exception ex)
    {
        // Handle other general errors (e.g., network issues)
        Console.WriteLine("Error calling service: " + ex.Message);
    }
}
  • Note: The using statement ensures the client is properly disposed after use.
  • The @return property matches the <return> element in your XSD definition (the @ is needed because return is a reserved keyword in C#).

3. If you want direct control over the generated code (optional)

If you prefer to have a visible .cs file in your project instead of the hidden service reference code, use the svcutil.exe tool (included with Visual Studio):

  1. Save your WSDL content as rmt_ws.wsdl and XSD content as rmt_ws.xsd in the same folder.
  2. Important: Edit the WSDL file to update the XSD reference from the remote URL to your local file. Change this line:
    <xsd:import namespace="http://remittance_ws/rmt_ws.wsdl" schemaLocation="https://www1.gsis.gr/wsicispay/rmt_ws?xsd=1"/>
    
    To:
    <xsd:import namespace="http://remittance_ws/rmt_ws.wsdl" schemaLocation="rmt_ws.xsd"/>
    
  3. Open the Visual Studio Developer Command Prompt, navigate to the folder with your files, and run this command:
    svcutil.exe rmt_ws.wsdl rmt_ws.xsd /out:RemittanceService.cs /namespace:MyApp.Remittance
    
  4. Add the generated RemittanceService.cs file to your project, then use the rmt_wsClient class from the MyApp.Remittance namespace just like in the example above.

Quick checks to avoid issues

  • Double-check your app config file (App.config/Web.config) to ensure the service endpoint address matches the one in the WSDL: https://www1.gsis.gr/wsicispay/rmt_ws
  • If you're testing in a non-production environment, make sure your network allows outbound calls to that URL.

内容的提问来源于stack exchange,提问作者rippergr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:41:42