简单的C#Web服务本地工作但不在服务器上工作

时间:2017-07-04 15:55:28

标签: c# visual-studio web-services web-config asmx

我有一个C#网络服务,很简单,

我有使用外部WSDL的Web引用,

在公司计算机上本地运行,但不在公司服务器上运行。

我在其他帖子上看到这可能与代理有关,但我已经厌倦了对webconfig有关代理的一些不同编辑,但我需要专家的帮助。

当我通过浏览器在服务器上运行webservice时按下调用时,我收到错误“无法连接到远程服务器”。

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://www.service-now.com/CatalogUpdateAutomationVariables">Unable to connect to the remote server</string> 

WEB CONFIG

<?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=\&quot;Web\&quot; /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;
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

经过对公司防火墙的一些调整后,我能够成功连接服务器。

感谢您的帮助