【问题标题】:Building a web service with WCF for usage by existing Java client using WSDL使用 WCF 构建 Web 服务以供使用 WSDL 的现有 Java 客户端使用
【发布时间】:2012-10-10 20:40:37
【问题描述】:

我有一个现有的 Java 客户端,我需要在 .NET 4.0 中构建一个 Web 服务。该接口已经使用 WSDL 文件定义,因此我创建了一个类库并使用 WSCF.blue 生成了服务器端存根(我也尝试了 svcutil,但没有成功)。 WSCF.blue 负责引用并添加文件(很棒的工具:-))所以我只用一些代码替换了生成的 System.NotImplementedException。然后我将结果托管在 ASP.NET 开发服务器中。

我想我需要一些额外的步骤,因为我得到了著名的“在服务'Hello' 实现的合同列表中找不到合同名称'WsdlWebService.IHello'。”在浏览器中查找服务时(请参阅WCF Contract Name 'IMyService' could not be found?)。但这里是一个 ServiceContractAttribute,我希望它能够完成这项工作。

如果有人能指出我所缺少的,我将不胜感激......

这是生成的接口和实现:



    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 + "!";
            }
        }
    } 

这是 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>

【问题讨论】:

    标签: wcf wsdl contract-first


    【解决方案1】:

    我只是猜测,因为我没有遇到该错误,但我注意到您在服务合同上设置了ConfigurationName = "IHello",但您在配置中将其称为“WsdlWebService.IHello”。我至少会检查配置名称是原子的还是仍然只是命名空间的一部分。

    【讨论】:

    • 感谢 DonAndre,这是缺少的细节,我现在可以在浏览器中看到网络服务器并访问 WSDL。不幸的是,我发现 WCF 服务与基于 Java 的原始服务器并不完全相同,因为在使用同一个客户端访问它时出现“无端点监听”错误。如果你知道可以帮助我的好资源,我将不胜感激。
    • 抱歉不知道。也许尝试使用相同的技术生成一个新的 java 客户端,看看它与服务访问点是否有任何不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多