简体   繁体   English

使用WCF构建Web服务以供现有Java客户端使用WSDL使用

[英]Building a web service with WCF for usage by existing Java client using WSDL

I have an existing Java client that I need to build a web service for in .NET 4.0. 我有一个现有的Java客户端,需要在.NET 4.0中为其构建Web服务。 The interface is already defined with a WSDL file so I created a class library and generated the server side stub using WSCF.blue (I also tried svcutil without success). 该接口已经使用WSDL文件定义,因此我创建了一个类库并使用WSCF.blue生成了服务器端存根(我也尝试了svcutil,但未成功)。 WSCF.blue takes care of the references and adding the files (great tool :-)) so I only replaced the generated System.NotImplementedException with some code. WSCF.blue处理引用并添加文件(出色的工具:-)),因此我仅用一些代码替换了生成的System.NotImplementedException。 Then I hosted the result in an ASP.NET development server. 然后,将结果托管在ASP.NET开发服务器中。

I guess I need some additional step since I get the famous "The contract name 'WsdlWebService.IHello' could not be found in the list of contracts implemented by the service 'Hello'." 我想我需要一些额外的步骤,因为我得到了著名的“合同名称‘WsdlWebService.IHello’无法通过该服务‘你好’实施合同的名单上找到。” when looking the service up in the browser (see WCF Contract Name 'IMyService' could not be found? ). 在浏览器中查找服务时(请参阅WCF合同名称'IMyService'找不到? )。 But here the is a ServiceContractAttribute of which I expect that it does the job. 但是,这里是ServiceContractAttribute,我希望它可以完成工作。

I would appreciate if someone could point to what I'm missing... 如果有人可以指出我所缺少的内容,我将不胜感激。

This is the generated interface and implementation: 这是生成的接口和实现:



    namespace WsdlWebService
    {
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        [System.ServiceModel.ServiceContractAttribute(Namespace="http://webservice.com", ConfigurationName="IHello")]
        public interface IHello
        {
            [System.ServiceModel.OperationContractAttribute(Action="http://webservice.com/IHello/helloName", ReplyAction="http://webservice.com/IHello/helloNameResponse")]
            [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
            [return: System.ServiceModel.MessageParameterAttribute(Name="helloNameReturn")]
            string helloName(string name);
        }

        [System.ServiceModel.ServiceBehaviorAttribute(InstanceContextMode=System.ServiceModel.InstanceContextMode.PerCall, ConcurrencyMode=System.ServiceModel.ConcurrencyMode.Single)]
        public class Hello : IHello
        {
            public virtual string helloName(string name)
            {
                return "Hello world from (via wsdl extraced server) " + name + "!";
            }
        }
    } 

This is the web.config: 这是web.config:



    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="false" targetFramework="4.0" />
      </system.web>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="MyServiceTypeBehaviors">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <services>
          <service name="WsdlWebService.Hello"
                 behaviorConfiguration="MyServiceTypeBehaviors">
            <endpoint address="" binding="basicHttpBinding"
                 contract="WsdlWebService.IHello"/>
            <endpoint contract="IMetadataExchange"
               binding="mexHttpBinding" address="mex"/>
          </service>
        </services>
      </system.serviceModel>
    </configuration>

I'm just guessing since I have not had that error, but I noticed you set the ConfigurationName = "IHello" on your service contract, but you're referring to it as "WsdlWebService.IHello" in the configuration. 我只是在猜测,因为我没有遇到该错误,但是我注意到您在服务合同上设置了ConfigurationName = "IHello" ,但是在配置中将其称为“ WsdlWebService.IHello”。 I would at least check if the configuration name is atomic or still only part of the namespace. 我至少会检查配置名称是否是原子名称,还是仅是名称空间的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM