1

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

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

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

我有以下文件

  1. myMainService.wsdl
  2. mySubService.wsdl
  3. myFirstXSD.xsd
  4. mySecondXSD.xsd
  5. myServiceSingleWSDL.wsdl
  6. 客户端代理代码(完成)
  7. 测试客户端(完成)

注意: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 服务主机,以便客户端可以连接到它或使用它

这里生成了 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);
                    }
            }

        }
4

1 回答 1

0

svcutil.exe 不会为您生成服务代码(听起来您已经发现了)。

如果原始服务由您/您的公司创建或拥有,或者您对源代码具有合法权利,您可以使用ReflectorJustDeCompile或类似工具(Reflector 有免费试用但您必须为长期使用付费,JustDecompile 是免费但不如 Reflector 灵活)对 DLL/EXE 进行逆向工程(假设您可以访问 DLL/EXE)。

如果这不是您的选择,您可以研究 Contract-First 开发,尽管我自己从未使用过它:

使用 Windows Communication Foundation 进行基于模式的开发

我还看到了对 Thinktecture 的WSCF.blue的引用,这可能值得一看。

于 2013-09-22T05:32:18.533 回答