我刚刚获得了一些包含 JAX-WS RI 的 XML 以及在MS Visual Studio中使用它的说明,以便为此Web服务生成 .NET客户端
我认为没有办法做到这一点。因为我们必须使用VS GUI来添加Web 服务参考。
是不是?
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.ttt.mysite.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.ttt.mysite.com/" name="wsttt">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.ttt.mysite.com/" schemaLocation="http://12.2.220.9:8081/ws-ttt/wsspi?xsd=1"/>
</xsd:schema>
</types>
...
答案 0 :(得分:0)
OK-Solution在这里https://code.msdn.microsoft.com/Generating-a-Web-Service-95ff4e10
Notice that this solution need that schema file xsd should be incorparated within wsdl.
public static void Generate(string wsdlPath, string outputFilePath)
{
if (File.Exists(wsdlPath) == false)
{
return;
}
ServiceDescription wsdlDescription = ServiceDescription.Read(wsdlPath);
ServiceDescriptionImporter wsdlImporter = new ServiceDescriptionImporter();
wsdlImporter.ProtocolName = "Soap12";
wsdlImporter.AddServiceDescription(wsdlDescription, null, null);
wsdlImporter.Style = ServiceDescriptionImportStyle.Server;
wsdlImporter.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties;
CodeNamespace codeNamespace = new CodeNamespace();
CodeCompileUnit codeUnit = new CodeCompileUnit();
codeUnit.Namespaces.Add(codeNamespace);
ServiceDescriptionImportWarnings importWarning = wsdlImporter.Import(codeNamespace, codeUnit);
if (importWarning == 0)
{
StringBuilder stringBuilder = new StringBuilder();
StringWriter stringWriter = new StringWriter(stringBuilder);
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
codeProvider.GenerateCodeFromCompileUnit(codeUnit, stringWriter, new CodeGeneratorOptions());
stringWriter.Close();
File.WriteAllText(outputFilePath, stringBuilder.ToString(), Encoding.UTF8);
}
else
{
Console.WriteLine(importWarning);
}
}