我有一个C#网络服务,它非常简单,
我有使用外部 WSDL 的网络参考,
在公司计算机上本地工作,但在公司服务器上不工作。
我在其他帖子中看到这可能与代理有关,但是我已经厌倦了对有关代理的网络配置进行了一些不同的编辑,但我需要专家的帮助。
当我通过浏览器在服务器上运行时按调用时,我收到错误"无法连接到远程服务器"。
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://www.service-now.com/CatalogUpdateAutomationVariables">Unable to connect to the remote server</string>
网页配置
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="InboundServiceNowWeb.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<system.web>
<compilation targetFramework="4.5.2" debug="true"/>
<httpRuntime targetFramework="4.5.2"/>
<customErrors mode="Off"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE="Web" /optionInfer+"/>
</compilers>
</system.codedom>
<system.serviceModel>
<bindings/>
<client/>
</system.serviceModel>
<applicationSettings>
<InboundServiceNowWeb.Properties.Settings>
<setting name="InboundServiceNowWeb_ServiceNowDev_ServiceNow_CatalogUpdateAutomationVariables" serializeAs="String">
<value>https://COMPANY.service-now.com/CatalogUpdateAutomationVariables.do?SOAP</value>
</setting>
</InboundServiceNowWeb.Properties.Settings>
</applicationSettings>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="false" />
</system.net>
</configuration>
<!--ProjectGuid: {55A9796B-1C01-4454-B0C3-942C1C8221B5}-->
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace InboundServiceNowWeb
{
/// <summary>
/// Summary description for ServiceNowInboundSOAP
/// </summary>
[WebService(Namespace = "http://www.service-now.com/CatalogUpdateAutomationVariables")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class ServiceNowInboundSOAP : System.Web.Services.WebService
{
[WebMethod]
public string UpdateCatalogRITM(string RITM, string ReturnCode, string ReturnMessage, string Comment)
{
// return "Hello World1";
/*
//SERVICE REFERENCE-SPECIFIC CODE
ServiceNowDev.ServiceNowSoapClient soapClient = new ServiceNowDev.ServiceNowSoapClient();
soapClient.ClientCredentials.UserName.UserName = "sys_ws_catalog";
soapClient.ClientCredentials.UserName.Password = "#####";
ServiceNowDev.update insert = new InboundServiceNowWeb.ServiceNowDev.update();
//ServiceNowDEV.update response = new ServiceNowDEV.updateResponse();
ServiceNowDev.updateResponse response = new InboundServiceNowWeb.ServiceNowDev.updateResponse();
*/
// WEB REFERENCE-SPECIFIC CODE
ServiceNowDev.ServiceNow_CatalogUpdateAutomationVariables soapClient = new InboundServiceNowWeb.ServiceNowDev.ServiceNow_CatalogUpdateAutomationVariables();
System.Net.ICredentials cred = new System.Net.NetworkCredential("sys_ws_catalog", "catalog01");
soapClient.Credentials = cred;
ServiceNowDev.update insert = new ServiceNowDev.update();
ServiceNowDev.updateResponse response = new ServiceNowDev.updateResponse();
// END OF WEB REFERENCE CODE */
insert.RequestNumber = RITM;
insert.ReturnCode = ReturnCode;
insert.ReturnMessage = ReturnMessage;
insert.Comments = Comment;
try
{
response = soapClient.update(insert);
return response.result;
}
catch (Exception error)
{
return error.Message;
// this.Response.Text = error.Message;
}
}
}
}
在对服务器的公司防火墙进行一些调整后,我能够成功连接。
感谢您的帮助