如何从ASP.NET MVC应用程序使用Web服务 [英] how to consume webservices from asp.net mvc application

查看:54
本文介绍了如何从ASP.NET MVC应用程序使用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个外部Web服务.

There is a external web services.

我可以从winform应用程序中调用它,但不能从asp.net mvc Web应用程序中调用它.

I can invoke it from my winform application, but I cannot invoke it from my asp.net mvc web application.

错误消息是这样的:

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://ihexds.nist.gov:9080/tf6/services/xdsrepositoryb that could accept the message. This is often caused by an incorrect address or SOAP action.

我的mvc Web应用程序是否需要配置以使用它?

Is there anything to configure for my mvc web application to consume it?

以下是我调用Web服务的代码

following is my code to invoke web services

WCF.Message msgInput, msgOutput;
msgInput = WCF.Message.CreateMessage(MESSAGE_VERSION, PROVIDEANDREGISTERDOCUMENTSETB_WSAACTION, request);
msgOutput = WCF.Message.CreateMessage(WCF.MessageVersion.Soap12WSAddressing10, "");

string endpointName = GetRepositoryEndPointName();
XDSRepository.XDSRepositoryClient client = new XDSRepository.XDSRepositoryClient(endpointName);

msgOutput = client.ProvideAndRegisterDocumentSet(msgInput);

推荐答案

从您的评论来看,我认为您的问题与代理服务器有关.我认为您正在使用公司内部的代理服务器.您必须在web.config文件中指定希望dotnet代码使用登录时使用的凭据.将此添加到您的web.config中,然后重试:

Judging from your comments, I think your problem is proxy server related. I think you're using a proxy server internal to your company. You have to specify in you web.config file that you want the dotnet code to use the credentials you're logged on with. Add this to your web.config and try again:

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true" >
    </defaultProxy>
</system.net>

您可能正在使用 .pac脚本.在这种情况下,您必须像这样明确地指定代理服务器:

It's also possible that you're working with a .pac script. In that case you have to explicitly specify the proxy server like so:

<system.net>
    <defaultProxy useDefaultCredentials="true">
        <proxy proxyaddress="http://proxyserver:proxyport"/>
    </defaultProxy>
</system.net>

这篇关于如何从ASP.NET MVC应用程序使用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆