首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF WCF服务连接问题

WCF WCF服务连接问题
EN

Stack Overflow用户
提问于 2016-07-10 11:41:43
回答 0查看 935关注 0票数 0

首先我要说的是,这是我第一次使用WCF web服务,在过去的3天里,我一直在与错误作斗争。这些问题在Stackoverflow上已经回答过很多次了,然而,我已经尝试了大多数解决方案,但还没有成功,所以我需要一些帮助来找出正确的方法。

现在介绍一些背景知识。我正在创建一个EpicorMVC5项目,我必须连接到Epicor服务( ASP.Net解决方案)。我的项目、ERP及其web服务都托管在一个内部IIS实例上。这些服务是使用BasicHTTP和NetTCP协议公开的。承载web服务和ERP的应用程序池使用标识。其中一个web服务名为Company.svc,它公开为:

代码语言:javascript
复制
<wsdl:service name="CompanySvcFacade">
    <wsdl:port name="BasicHttpBinding_CompanySvcContract" binding="tns:BasicHttpBinding_CompanySvcContract">
        <soap:address location="http://pilotserver/ERP100700/Ice/BO/Company.svc"/>
    </wsdl:port>
    <wsdl:port name="CustomBinding_CompanySvcContract" binding="tns:CustomBinding_CompanySvcContract">
        <soap12:address location="net.tcp://pilotserver/ERP100700/Ice/BO/Company.svc"/>
        <wsa10:EndpointReference>
            <wsa10:Address>net.tcp://pilotserver/ERP100700/Ice/BO/Company.svc</wsa10:Address>
            <Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
                <Upn>pilotserver\Administrator</Upn>
            </Identity>
        </wsa10:EndpointReference>
    </wsdl:port>
</wsdl:service>

在我的项目中,我的web.config包含以下内容:

代码语言:javascript
复制
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_CompanySvcContract" />
  </basicHttpBinding>
  <customBinding>
    <binding name="CustomBinding_CompanySvcContract">
      <security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
        requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
        <localClientSettings detectReplays="false" />
        <localServiceSettings detectReplays="false" />
      </security>
      <textMessageEncoding />
      <windowsStreamSecurity />
      <tcpTransport />
    </binding>
  </customBinding>
</bindings>
<client>
  <endpoint address="http://pilotserver/ERP100700/Ice/BO/Company.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_CompanySvcContract"
    contract="CompanyService.CompanySvcContract" name="BasicHttpBinding_CompanySvcContract" />
  <endpoint address="net.tcp://pilotserver/ERP100700/Ice/BO/Company.svc"
    binding="customBinding" bindingConfiguration="CustomBinding_CompanySvcContract"
    contract="CompanyService.CompanySvcContract" name="CustomBinding_CompanySvcContract">
    <identity>
      <userPrincipalName value="pilotserver\Administrator" />
    </identity>
  </endpoint>
</client>

我正在尝试使用以下代码在客户端使用web服务:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using EpicorTestApp.CompanyService;
using NLog;
namespace EpicorTestApp.Controllers
{
    public class HomeController : Controller
    {
        CompanySvcContractClient CompanyService = new CompanySvcContractClient("CustomBinding_CompanySvcContract");
        //CompanySvcContractClient CompanyService = new CompanySvcContractClient("BasicHttpBinding_CompanySvcContract");
        private Logger logger = LogManager.GetCurrentClassLogger();
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            bool morePages = false;

            CompanyService.ClientCredentials.UserName.UserName = "Administrator";
            CompanyService.ClientCredentials.UserName.UserName = "myPassword";
            CompanyListTableset companyList = CompanyService.GetList("", 0, 0, out morePages);
            CompanyListTable companies = companyList.CompanyList;
            foreach (CompanyListRow companyListRow in companies)
            {
                logger.Info("Company: " + companyListRow.Company);
            }           
            return View();
        }
    }
}

对于客户端绑定,我尝试了BasicHttp和NetTCP (以CustomBinding身份),这两种方法都会导致一些错误。在创建BasicHttp绑定时,我使用以下服务引用配置:

在运行此配置时,我收到“访问被拒绝。异常详细信息: System.ServiceModel.Security.SecurityAccessDeniedException:访问被拒绝”的错误。

对于nettcp绑定,当我试图创建一个服务引用时,我收到一条错误消息:“无法识别URI前缀。元数据包含无法解析的引用: net.tcp://localhost/ERP100700/Ice/BO/Company.svc'.我尝试在url中同时使用本地主机和pilotserver。

我尝试在调试模式(ISS-Express)下运行应用程序并将其发布到IIS,但结果相同。我做错了什么?我该如何解决这个问题?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38288357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档