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
ePaymentsservice reference, then expand theReference.svcmapfolder. You'll find the generated.csfile there (usually namedReference.cs). - Alternatively, open the Object Browser (View → Object Browser), navigate to the
ePaymentsnamespace, and check for these key types:rmt_wsClient: The main client class to call the serviceremittanceXml: The request typeremittanceXmlResponse: The response typeUnsupportedEncodingException: 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
usingstatement ensures the client is properly disposed after use. - The
@returnproperty matches the<return>element in your XSD definition (the@is needed becausereturnis 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):
- Save your WSDL content as
rmt_ws.wsdland XSD content asrmt_ws.xsdin the same folder. - Important: Edit the WSDL file to update the XSD reference from the remote URL to your local file. Change this line:
To:<xsd:import namespace="http://remittance_ws/rmt_ws.wsdl" schemaLocation="https://www1.gsis.gr/wsicispay/rmt_ws?xsd=1"/><xsd:import namespace="http://remittance_ws/rmt_ws.wsdl" schemaLocation="rmt_ws.xsd"/> - 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 - Add the generated
RemittanceService.csfile to your project, then use thermt_wsClientclass from theMyApp.Remittancenamespace 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
相关产品推荐
相关产品推荐

