【问题标题】:Trouble connecting to WSDL无法连接到 WSDL
【发布时间】:2011-09-01 12:29:09
【问题描述】:

我获得了一个使用 WSDL 文件连接到 Web 服务的 SDK。我在自述文件中获得了示例代码以及有关如何设置文件的分步说明,但即使遵循所有内容,代码也不会编译。

说明和代码在这里。 http://dl.dropbox.com/u/3425987/README.txt

WSDL 文件在这里http://dl.dropbox.com/u/3425987/arm-inlined.wsdl

好像没有找到 ArmServiceImplService。

非常感谢任何有关我做错的帮助。

编辑:我唯一没有按照说明做的事情是我使用的是 VS 2010,而不是 2008。我不认为这会是问题,但我已经没有其他选择了。

【问题讨论】:

  • 也许是一些示例代码?显然问题出在某个地方,而不是在自述文件或 wsdl 中。
  • 唯一的问题是目前我只使用示例代码并且不起作用。
  • 我的错……对不起。我以为它只是说明。

标签: c# .net soap wsdl


【解决方案1】:

作为 WSDL 的一部分,有一个用于访问 SOAP 服务的位置/URL - 根据 WSDL,它是:

http://localhost:8080/ARM/ARM/

此位置会导致您的客户端尝试访问其运行所在系统上的端口 8080...除非您在那里运行 SOAP 服务,否则这将无法正常工作(连接被拒绝和/或超时)...

来自自述文件中的示例源:

// TODO: Replace with live server URL when ready
armService.Url = "http://localhost:8081/ARM/ARM/";

此注释告诉您将 URL 替换为实时服务器 URL...

根据您的问题,我假设您没有替换 URL/没有实时服务器 URL?

编辑 - 根据 OP 的评论:

如果您的代码未编译,您似乎已跳过第 7 点并按照自述文件中的说明进行操作

7) Visual Studio 打开新创建的项目后,右键单击 在 SampleArmClient 上 解决方案资源管理器并选择“添加服务引用”

8) 在 “添加服务引用”对话框,在标有 URL 的框中输入 a) 来自真实或“模拟”ARM 服务的 WSDL 的 URL (用于说明 关于启动“模拟”ARM 服务,请参阅第 7 节。) 例子, 如果“模拟”服务在端口 8081 上启动,则指向 服务 将是http://localhost:8081/ARM/ARM?WSDL.Please 请注意 要从内部使用的 URL 您的代码是 http://:/ARM/ARM。它不是 包含“?WSDL” - 那 后缀严格用于发现 Web 服务。 b) 的 wsdl 在解压后所在的磁盘上的位置 分配。 例如,如果分发被解压到 c:/temp 目录 网址是 c:\temp\arm\src\main\resources\gov\hud\arm\wsdl\arm-inlined.wsdl。 (这是其中包含模式的 WSDL 版本,因此 .NET 可以 解析没有外部架构的引用。)

【讨论】:

  • 我的本地机器上确实有一个在 8081 上运行的服务。问题是 ArmServiceImplService 获得了找不到类型或命名空间名称“ArmServiceImplService”(您是否缺少 using 指令或程序集引用?)
  • 问题是我已经这样做了,但它似乎仍然不起作用。我在不同的时间完成了 8a 和 8b,但都没有工作。
  • 对不起,但我不明白......如果你做了所有这些,结果是什么? VS 是否生成“代理类”?它会给出错误消息吗?您的“代理类”的名称是什么(也许您需要修改示例代码以说明 VS 生成的代理类名称)?
【解决方案2】:

为您解决最后一个难题。我查看了我的电子邮件以查看说明中 7/8 的确切问题,这就是我向 HUD 报告的内容:

在您为 Visual Studio 2008 提供的说明中,第 8 项告诉您添加服务引用。现在部分我做对了,部分我没有做对,因为我对 .net 太陌生了,但是,您需要调整该行以阅读添加新的 Web 参考(服务参考不再是一个选项)而不是服务引用,告诉他们将其命名为 ARM 非常重要

这也适用于我昨晚设法使用的 VS2010。正如您所知,我编辑了原始代码帖子以删除中断的行,因此只需更改 id 和路径,您应该一切顺利。我针对从 hud 支持 (Andrey) 获得的开发 url 运行它,而不是尝试在我的机器上运行该服务。我建议您也这样做,因为如果他们的样品已经过时了,那么我敢打赌他们提供的样品服务也是如此。开发 url 工作得很好,尽管我确实在那里发现了一些差异。此后它们已被修复,因此它应该是测试您的 xml 提交文件的最佳位置。

【讨论】:

    【解决方案3】:

    好吧,奇迹永远不会停止。我刚刚对下面的代码进行了另一次拍摄。当然,这里给了我一个错误:

        api client = new api(); 
        client.PreAuthenticate = true; 
        client.Credentials = new NetworkCredential(credentials.UserName, credentials.Password); 
    

    所以我把它删掉并重新运行,我收到了 HUD 的回复。那个怎么样!!它只发送代理文件,但它连接、发送文件,并将响应返回给我。现在我所要做的就是创建我需要的其他功能,以及将每家公司的凭据传递给它的方法以及如何获取响应,以便我可以将它们记录到我的 asp 站点中,一切都会好起来的再次。 bin 文件显示它正在创建一个 exe,因此希望我可以从我的 asp 代码中调用它,将凭据和每个公司的文件路径发送给它,它可以一次发送一个,获取响应并记录它。然后稍后运行响应以确保所有数据都通过验证。

    还有很多工作要做,但是,这是向前迈出的一大步。希望这会有所帮助,如果你打败了我,请告诉我。我是一名承包商,可能永远无法获得完成项目这一方面的报酬,但很高兴知道我现在可以走这条路了。我可能只是为了满足我击败机器的需要。 :) 但是如果你打败了我,请把决赛发给我,我会确保 HUD 得到完整的更新,这样其他人就不必把头撞到墙上了。

    【讨论】:

      【解决方案4】:

      首先,我遇到了同样的问题,所以我还没有所有的答案。但是使用 VS2010 你确实需要添加一些代码来建立连接。问题是您必须在标头中进行身份验证,并且使用 VS2008 及更高版本,它不会这样做。

      现在,还有其他问题。如果你想运行 databag 4 那就是。他们给我们的代码是针对早期数据包的,并且不运行数据包 4 发送/接收函数,因为它不包含它们的样本。我已经要求他们把它包括在内,但谁知道这需要多长时间。

      另外,如上所述,步骤 7 / 8 至关重要,方向不正确。我也已通知支持人员,但截至我上次检查时,他们尚未更新注释以包含该内容。抱歉,我现在不记得具体细节了,但我在第三次或第四次阅读屏幕时发现了一些非常简单的问题。

      正如您将在下面的代码中注意到的那样,我在正确的方向上取得了一些进展,但我不是 .net 开发人员。我是一个经典的 asp 人,所以我仍然无法以这种方式获得它的全部功能,并且目前无法使用 SOAP UI 工具进行上传。这意味着我必须手动完成所有 30 家公司,一次一个文件。每个 4 个文件。尽管如此,我在一天之内就完成了工作,并且为我的时间付出了丰厚的回报,所以没关系,但我对迄今为止获得的支持感到沮丧,所以如果您从中了解更多信息,请告诉我。

          using System;
          using System.Collections.Generic;
          using System.Text;
          using ARMService.ARM;
          using System.Net;
          using System.IO;
          using System.Threading;
      
          namespace ARMService
          {
            public partial class api : System.Web.Services.Protocols.SoapHttpClientProtocol
          {
          //added "protected overide" to get past the pre-auth issue with VS2008 and above since I'm  running VS2010
          //Now this is in place, you will send the authentication header at the first request. 
          //Since this implementation is using the credentials from the WebClientProtocol, you will be required to set these in advance. 
          //But I guess you were doing that anyways. Furthermore, I chose to only do the pre-authentication if the PreAuthenticate 
          //property was set to true. (deactivated if statement so it will always preauth.)
          //So if you want to consume this service, this is how you would initiate it;
          //api client = new api();
          //client.PreAuthenticate = true;
          //client.Credentials = new NetworkCredential("username", "password");
      
          protected override System.Net.WebRequest GetWebRequest(Uri uri)
          {
              HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
              //              if (PreAuthenticate)    //removed if statement because I want all items to pre-auth
              //              {
              NetworkCredential networkCredentials = Credentials.GetCredential(uri, "Basic");
              if (networkCredentials != null)
              {
                  byte[] credentialBuffer = new UTF8Encoding().GetBytes(networkCredentials.UserName + ":" + networkCredentials.Password);
                  request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credentialBuffer);
              }
              else
              {
                  throw new ApplicationException("No network credentials");
              }
              //              }
              return request;
          }
      }
      
      
      class Program
      {
          static void Main(string[] args)
          {
              ArmServiceImplService armService = new ArmServiceImplService();
              // TODO: Replace with live server URL when ready
              armService.Url = "https://HUD will give you the url/ARM/ARM/";
              armService.PreAuthenticate = true;
              NetworkCredential credentials = new NetworkCredential();
              // TODO: Replace with userid/password issued by HUD for HCS system when ready
              credentials.UserName = "yourHUDMXnumber";
              credentials.Password = "yourpassword";
      
              armService.Credentials = credentials;
      
              //These three removed per second post and fixed the last issue
              //api client = new api();
              //client.PreAuthenticate = true;
              //client.Credentials = new NetworkCredential(credentials.UserName, credentials.Password);
      
              //removed for now to try only postAgencyData
              //doPing(armService);
              //doGetReference(armService);
              //postSubmissionResponse submissionId = doPostSubmission(armService);
      
              //fixed
              postSubmissionResponse psr = AgencyData(armService);
              while (dopostAgencyDataResponse(armService, psr) != true)
              {
                  // sleep for 60 seconds before checking agin.
                  Thread.Sleep(60000);
              }
          }
      
          private static void doGetReference(ArmServiceImplService armService)
          {
              getReference getReference = new getReference();
              // TODO: Replace 80000 with your agency HCS id.
              getReference.agcHcsId = 80000;
              getReference.referenceId = 0;
              referenceItem[] referenceItems = armService.getReference(getReference);
              foreach (referenceItem referenceItem in referenceItems)
              {
                  Console.WriteLine(referenceItem.id);
                  Console.WriteLine(referenceItem.name);
                  Console.WriteLine(referenceItem.longDesc);
                  Console.WriteLine(referenceItem.shortDesc);
              }
          }
      
          private static void doPing(ArmServiceImplService armService)
          {
              ping pingIn = new ping();
              // TODO: Replace 80000 with your agency HCS id.
              pingIn.agcHcsId = 80000;
              string pingString = armService.ping(pingIn);
              Console.WriteLine(pingString);
          }
      
      
      
      
          private static postSubmissionResponse AgencyData(ArmServiceImplService armService)
          {
              postAgencyData AgencyData = new postAgencyData();
              submissionHeader40 header = new submissionHeader40();
              // TODO: Replace 80000 with your agency HCS id.
              header.agcHcsId = 80000;
              header.agcName = "Your Agency Name";
              // TODO: Replace 8 with your CMS vendor id issued to you by ARM Development Team.
              header.fiscalYearId = 17;
              header.reportingPeriodId = 3;
              header.cmsVendorId = yourVendorNUmber;
              AgencyData.submissionHeader40 = header;
      
              // TODO: Replace fake databag with valid databag of your own
              FileStream file = new FileStream("c:/Users/Public/Documents/AgencyProfileData.xml", FileMode.Open, FileAccess.Read);
              StreamReader sr = new StreamReader(file);
              string str = sr.ReadToEnd();
      
              System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
              AgencyData.submissionData = encoding.GetBytes(str);
      
              //fixed
              postSubmissionResponse psr = armService.postAgencyData(AgencyData);
              Console.WriteLine("Submitted Data returned id : " + psr.submissionId);
              return psr;
          }
      
          private static Boolean dopostAgencyDataResponse(ArmServiceImplService armService,
              postSubmissionResponse postAgencyDataResponse)
          {
              getSubmissionInfo getSubmissionInfo = new getSubmissionInfo();
              // TODO: Replace 80000 with your agency HCS id.
              getSubmissionInfo.agcHcsId = 80000;
              getSubmissionInfo.submissionId = postAgencyDataResponse.submissionId;
              getSubmissionInfoResponse response = armService.getSubmissionInfo(getSubmissionInfo);
              Console.WriteLine("SubmissionInfo Status Date = " + response.statusDate);
              Console.WriteLine("SubmissionInfo Status Message = " + response.statusMessage);
              // if Done or Error returned, then return true to stop polling server.
              if (response.statusMessage.Equals("DONE") || response.statusMessage.Contains("ERROR"))
              {
                  return true;
              }
              else
              {
                  return false;
              }
          }
      }
      }
      

      【讨论】:

        【解决方案5】:

        我只是想我会跟进这个。上述解决方案适用于除我需要传输的较大文件之外的所有文件。为了纠正这个问题,我只是从 program.cs 页面中删除(剪切)了受保护的覆盖语句,并将其复制到 references.cs 页面中,并仅进行了两次调整。新的声明是:

        protected override System.Net.WebRequest GetWebRequest(Uri uri)
                {
                    HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
                    if (PreAuthenticate)
                    {
                        NetworkCredential networkCredentials = Credentials.GetCredential(uri, "Basic");
                        if (networkCredentials != null)
                        {
                            byte[] credentialBuffer = new UTF8Encoding().GetBytes(networkCredentials.UserName + ":" + networkCredentials.Password);
                            request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credentialBuffer);
                        }
                        else
                        {
                            throw new ApplicationException("No network credentials");
                        }
                    }
                    request.KeepAlive = false;
                    return request;
                }
        

        保存后,我可以保持连接足够长的时间来传输非常大的文件。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-08-20
          • 2013-04-11
          • 2016-10-26
          • 1970-01-01
          • 2017-08-23
          • 2018-02-07
          • 1970-01-01
          相关资源
          最近更新 更多