如何从现有的WSDL生成WCF服务HOST& XSD文件

时间:2013-09-22 02:59:38

标签: xml wcf web-services xsd wsdl

我有现有的WSDL&来自我们的一个服务器的XSD文件,该服务器使用WAS(Windows激活服务)运行带有ASP.NET 4.5的IIS 8。我正在使用VS 2012进行该项目。我没有WCF服务主机的原始代码,所以我需要从现有的WSDL& amp;创建WCF主机。 XSD文件。

我已经拥有客户端代理代码,即客户端已完成部分。

我需要从现有的WSDL& amp;中生成将在IIS 8服务器中托管的WCF服务主机。 XSD文件?不是客户代理代码 - 我已经完成了。

我有以下文件

  1. myMainService.wsdl
  2. mySubService.wsdl
  3. myFirstXSD.xsd
  4. mySecondXSD.xsd
  5. myServiceSingleWSDL.wsdl
  6. 客户端代理代码(完成)
  7. 测试客户端(完成)
  8. 注意:MyMainService.wsdl指向mySubService.wsdl,其中包含调用myFirstXSD.xsd和mySecondXSD.xsd的代码 我也有单个WSDL,即myServiceSingleWSDL.wsdl

    我读了如何使用SvcUtil.exe& Disco.exe,但我不知道如何正确地做到这一点。大多数相似的问题都没有回答这个问题,只是绕过它。

    如果您可以包含用于执行此操作的命令,请逐步进行操作。任何帮助都会很受欢迎。

    所以我运行以下命令从上面的文件生成下面的代码 SvcUtil / mc / language:C#/ out:IService1.cs /n:*,Contoso.WcfServiceHost MyMainService.wsdl MySubService.wsdl MyFirstXSD.xsd MySecondXSD.xsd

    从这里开始下一步是什么?生成将在IIS 8中托管的WCF服务HOST,以便客户端可以连接到它或使用它

    这里生成了Web.config文件

          <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <system.serviceModel>
            <bindings>
              <wsHttpBinding>
                <binding name="WSHttpBinding_IMyService">
                  <security mode="None" />
                </binding>
              </wsHttpBinding>
            </bindings>
            <client>
              <endpoint address="http://contoso.com/MyService.svc"
                binding="wsHttpBinding"  bindingConfiguration="WSHttpBinding_IMyService"
                contract="IMyService" name="WSHttpBinding_IMyService">
                <identity>
                  <dns value="localhost" />
                </identity>
              </endpoint>
            </client>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"   multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>
          </system.serviceModel>
         </configuration>
    

    以下是生成的Iservice1.cs文件

            //------------------------------------------------------------------------------
            // <auto-generated>
            //     This code was generated by a tool.
            //     Runtime Version:4.0.30319.18051
            //
            //     Changes to this file may cause incorrect behavior and will be lost if
            //     the code is regenerated.
            // </auto-generated>
            //------------------------------------------------------------------------------
    
    
            namespace Contoso.WcfServiceHost
            {
    
    
                [System.ServiceModel.ServiceContractAttribute(Namespace = "http://contoso.com/MyService.svc", ConfigurationName = "IMyService")]
                public interface IMyService
                {
    
                    [System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Login", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LoginResponse")]
                    LoginResponse Login(LoginRequest request);
    
                    [System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Login", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LoginResponse")]
                    System.Threading.Tasks.Task<LoginResponse> LoginAsync(LoginRequest request);
    
                    [System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Logout", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LogoutResponse")]
                    LogoutResponse Logout(LogoutRequest request);
    
                    [System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/Logout", ReplyAction = "http://contoso.com/MyService.svc/IMyService/LogoutResponse")]
                    System.Threading.Tasks.Task<LogoutResponse> LogoutAsync(LogoutRequest request);
    
                    [System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/GetId", ReplyAction = "http://contoso.com/MyService.svc/IMyService/GetIdResponse")]
                    GetIdResponse GetId(GetIdRequest request);
    
                    [System.ServiceModel.OperationContractAttribute(Action = "http://contoso.com/MyService.svc/IMyService/GetId", ReplyAction = "http://contoso.com/MyService.svc/IMyService/GetIdResponse")]
                    System.Threading.Tasks.Task<GetIdResponse> GetIdAsync(GetIdRequest request);
                }
    
    
                [System.ServiceModel.MessageContractAttribute(WrapperName = "Login", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
                public partial class LoginRequest
                {
    
                    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
                    public string login;
    
                    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 1)]
                    public string password;
    
                    public LoginRequest()
                        {
                        }
    
                    public LoginRequest(string login, string password)
                        {
                        this.login = login;
                        this.password = password;
                        }
                }
    
    
                [System.ServiceModel.MessageContractAttribute(WrapperName = "LoginResponse", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
                public partial class LoginResponse
                {
    
                    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
                    public System.Guid LoginResult;
    
                    public LoginResponse()
                        {
                        }
    
                    public LoginResponse(System.Guid LoginResult)
                        {
                        this.LoginResult = LoginResult;
                        }
                }
    
    
                [System.ServiceModel.MessageContractAttribute(WrapperName = "Logout", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
                public partial class LogoutRequest
                {
    
                    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
                    public System.Guid sessionId;
    
                    public LogoutRequest()
                        {
                        }
    
                    public LogoutRequest(System.Guid sessionId)
                        {
                        this.sessionId = sessionId;
                        }
                }
    
    
                [System.ServiceModel.MessageContractAttribute(WrapperName = "LogoutResponse", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
                public partial class LogoutResponse
                {
    
                    public LogoutResponse()
                        {
                        }
                }
    
    
                [System.ServiceModel.MessageContractAttribute(WrapperName = "GetId", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
                public partial class GetIdRequest
                {
    
                    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
                    public System.Guid sessionId;
    
                    public GetIdRequest()
                        {
                        }
    
                    public GetIdRequest(System.Guid sessionId)
                        {
                        this.sessionId = sessionId;
                        }
                }
    
    
                [System.ServiceModel.MessageContractAttribute(WrapperName = "GetIdResponse", WrapperNamespace = "http://contoso.com/MyService.svc", IsWrapped = true)]
                public partial class GetIdResponse
                {
    
                    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://contoso.com/MyService.svc", Order = 0)]
                    public long GetIdResult;
    
                    public GetIdResponse()
                        {
                        }
    
                    public GetIdResponse(long GetIdResult)
                        {
                        this.GetIdResult = GetIdResult;
                        }
                }
    
    
                public interface IMyServiceChannel : IMyService, System.ServiceModel.IClientChannel
                {
                }
    
    
                public partial class MyServiceClient : System.ServiceModel.ClientBase<IMyService>, IMyService
                {
    
                    public MyServiceClient()
                        {
                        }
    
                    public MyServiceClient(string endpointConfigurationName) :
                        base(endpointConfigurationName)
                        {
                        }
    
                    public MyServiceClient(string endpointConfigurationName, string remoteAddress) :
                        base(endpointConfigurationName, remoteAddress)
                        {
                        }
    
                    public MyServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
                        base(endpointConfigurationName, remoteAddress)
                        {
                        }
    
                    public MyServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
                        base(binding, remoteAddress)
                        {
                        }
    
                    public LoginResponse Login(LoginRequest request)
                        {
                        return base.Channel.Login(request);
                        }
    
                    public System.Threading.Tasks.Task<LoginResponse> LoginAsync(LoginRequest request)
                        {
                        return base.Channel.LoginAsync(request);
                        }
    
                    public LogoutResponse Logout(LogoutRequest request)
                        {
                        return base.Channel.Logout(request);
                        }
    
                    public System.Threading.Tasks.Task<LogoutResponse> LogoutAsync(LogoutRequest request)
                        {
                        return base.Channel.LogoutAsync(request);
                        }
    
                    public GetIdResponse GetId(GetIdRequest request)
                        {
                        return base.Channel.GetId(request);
                        }
    
                    public System.Threading.Tasks.Task<GetIdResponse> GetIdAsync(GetIdRequest request)
                        {
                        return base.Channel.GetIdAsync(request);
                        }
                }
    
            }
    

1 个答案:

答案 0 :(得分:0)

svcutil.exe不会为您生成服务代码(因为它听起来像您已经发现的那样)。

如果原始服务是由您/您的公司创建或拥有的,或者您拥有源代码的合法权利,则可以使用ReflectorJustDeCompile或类似工具(Reflector有免费试用版)但是你需要为长期使用付费,JustDecompile是免费的,但不像Reflector那样灵活,以反转工程师的DLL / EXE(假设你有权访问DLL / EXE)。

如果这不是您的选择,您可以查看契约优先开发,但我自己从未使用过它:

Schema-based Development with Windows Communication Foundation

我也看过对Thinktecture的WSCF.blue的引用,这可能值得一看。