我有来自我们的一台服务器的现有 WSDL 和 XSD 文件,该服务器使用 WAS(Windows 激活服务)运行带有 ASP.NET 4.5 的 IIS 8。我正在为该项目使用 VS 2012。我没有 WCF 服务主机的原始代码,因此我需要从现有的 WSDL 和 XSD 文件创建 WCF 主机。
我已经有客户端代理代码,即客户端已完成。
我需要从现有的 WSDL 和 XSD 文件生成将在 IIS 8 服务器中托管的 WCF 服务主机?不是客户端代理代码 - 我已经完成了。
我有以下文件
- myMainService.wsdl
- mySubService.wsdl
- myFirstXSD.xsd
- mySecondXSD.xsd
- myServiceSingleWSDL.wsdl
- 客户端代理代码(完成)
- 测试客户端(完成)
注意: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);
}
}
}