首先,我遇到了同样的问题,所以我还没有所有的答案。但是使用 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;
}
}
}
}