读书人

C++ Builder6调用C#写的WebService出

发布时间: 2013-01-05 15:20:40 作者: rapoo

C++ Builder6调用C#写的WebService出
C++ Builder6调用C#写的WebService出,提示:
Object reference not set to an instance of an object.
这个WebService用C#写的应用程序可以正常调用.

在网上找了一个WebService测试了下:
http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx
调用getMobileCodeInfo 函数
返回:手机号码错误 http://www.webxml.com.cn

C++ Builder代码:
Unit1.cpp

//---------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
_di_MobileCodeWSSoap TForm1::GetWebService()
{
if(!ss)
{
HTTPRIO1->QueryInterface(ss);
}
return ss;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString mobileid = Memo2->Text.Trim();
if(getMobileCodeInfo)
{
Memo1->Text = "Mobile ID:" + mobileid;
Memo1->Lines->Add(getMobileCodeInfo->getMobileCodeInfo(mobileid," "));
}
}
//---------------------------------------



Unit1.h

//---------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Rio.hpp>
#include <SOAPHTTPClient.hpp>
#include "MobileCodeWS.h"
//---------------------------------------
class TForm1 : public TForm
{
__published:// IDE-managed Components
TMemo *Memo1;
TEdit *Edit1;
TMemo *Memo2;
TButton *Button1;
THTTPRIO *HTTPRIO1;
void __fastcall Button1Click(TObject *Sender);
private:// User declarations
public:// User declarations
__fastcall TForm1(TComponent* Owner);


_di_MobileCodeWSSoap ss;
_di_MobileCodeWSSoap GetWebService();
__property
_di_MobileCodeWSSoap getMobileCodeInfo = { read=GetWebService };
};
//---------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------
#endif




WebService自动生成的:
MobileCodeWS.h

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2009/9/16 上午 09:41:37 - $Revision: 1.0.1.0.1.82 $)
// ************************************************************************ //

#ifndef MobileCodeWSH
#define MobileCodeWSH

#include <System.hpp>
#include <InvokeRegistry.hpp>
#include <XSBuiltIns.hpp>
#include <SoapHTTPClient.hpp>


namespace NS_MobileCodeWS {

// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema"

typedef DynamicArray<AnsiString> ArrayOfString; /* "http://WebXml.com.cn/" */

// ************************************************************************ //
// Namespace : http://WebXml.com.cn/
// soapAction: http://WebXml.com.cn/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : MobileCodeWSSoap
// service : MobileCodeWS
// port : MobileCodeWSSoap
// URL : http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx
// ************************************************************************ //
__interface INTERFACE_UUID("{48CFEB9F-FF3E-298B-BA04-DD79C8DC675C}") MobileCodeWSSoap : public IInvokable
{
public:
virtual AnsiString getMobileCodeInfo(const AnsiString mobileCode, const AnsiString userID) = 0;
virtual ArrayOfString getDatabaseInfo() = 0;


};
typedef DelphiInterface<MobileCodeWSSoap> _di_MobileCodeWSSoap;

_di_MobileCodeWSSoap GetMobileCodeWSSoap(bool useWSDL=false, AnsiString addr="");



#endif // __MobileCodeWS_h__

}; // NS_MobileCodeWS

#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace NS_MobileCodeWS;
#endif




MobileCodeWS.cpp

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2009/9/16 上午 09:41:37 - $Revision: 1.0.1.0.1.82 $)
// ************************************************************************ //

#include <vcl.h>
#pragma hdrstop

#if !defined(MobileCodeWSH)
#include "MobileCodeWS.h"
#endif



namespace NS_MobileCodeWS {

_di_MobileCodeWSSoap GetMobileCodeWSSoap(bool useWSDL, AnsiString addr)
{
static const char* defWSDL= "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl";
static const char* defURL = "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx";
static const char* defSvc = "MobileCodeWS";
static const char* defPrt = "MobileCodeWSSoap";
if (addr=="")
addr = useWSDL ? defWSDL : defURL;
THTTPRIO* rio = new THTTPRIO(0);
if (useWSDL) {
rio->WSDLLocation = addr;
rio->Service = defSvc;
rio->Port = defPrt;
} else {
rio->URL = addr;
}
_di_MobileCodeWSSoap service;
rio->QueryInterface(service);
if (!service)
delete rio;
return service;
}


// ************************************************************************ //
// This routine registers the interfaces and types used by invoke the SOAP
// Service.
// ************************************************************************ //
static void RegTypes()
{
/* MobileCodeWSSoap */
InvRegistry()->RegisterInterface(__interfaceTypeinfo(MobileCodeWSSoap), L"http://WebXml.com.cn/", L"utf-8");
InvRegistry()->RegisterDefaultSOAPAction(__interfaceTypeinfo(MobileCodeWSSoap), L"http://WebXml.com.cn/%operationName%");
RemClassRegistry()->RegisterXSInfo(__arrayTypeinfo(ArrayOfString), L"http://WebXml.com.cn/", L"ArrayOfString");
}
#pragma startup RegTypes 32

}; // NS_MobileCodeWS




[解决办法]
帮顶一下!!
------解决方案--------------------


来学习

读书人网 >C++ Builder

热点推荐