1
我是C++新手。我已經寫在c#中的上傳文件wcf,並有gsoap2.8生成header.h文件。gsoap c文件讀取
這是我在c#中的上傳文件wcf服務。
public void UploadFile(RemoteFileInfo request)
{
FileStream targetStream = null;
Stream sourceStream = request.FileByteStream;
string uploadFolder = @"C:\temp\upload\copyHere";
string filePath = Path.Combine(uploadFolder, request.FileName);
using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
//read from the input stream in 6K chunks
//and save to output stream
const int bufferLen = 65000;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}
}
下面是一個WSDL通過gsoap2.8產生header.h代碼:
class SOAP_CMAC xsd__base64Binary
{
public:
unsigned char *__ptr;
int __size;
char *id; /* optional element of type xsd:string */
char *type; /* optional element of type xsd:string */
char *options; /* optional element of type xsd:string */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 8; } /* = unique id SOAP_TYPE_xsd__base64Binary */
virtual void soap_default(struct soap*);
virtual void soap_serialize(struct soap*) const;
virtual int soap_put(struct soap*, const char*, const char*) const;
virtual int soap_out(struct soap*, const char*, int, const char*) const;
virtual void *soap_get(struct soap*, const char*, const char*);
virtual void *soap_in(struct soap*, const char*, const char*);
xsd__base64Binary() { xsd__base64Binary::soap_default(NULL); }
virtual ~xsd__base64Binary() { }
};
class SOAP_CMAC _ns1__RemoteFileInfo
{
public:
xsd__base64Binary FileByteStream; /* SOAP 1.2 RPC return element (when namespace qualified) */ /* required element of type ns2:StreamBody */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 14; } /* = unique id SOAP_TYPE__ns1__RemoteFileInfo */
virtual void soap_default(struct soap*);
virtual void soap_serialize(struct soap*) const;
virtual int soap_put(struct soap*, const char*, const char*) const;
virtual int soap_out(struct soap*, const char*, int, const char*) const;
virtual void *soap_get(struct soap*, const char*, const char*);
virtual void *soap_in(struct soap*, const char*, const char*);
_ns1__RemoteFileInfo() { _ns1__RemoteFileInfo::soap_default(NULL); }
virtual ~_ns1__RemoteFileInfo() { }
};
這是我TEST.CPP代碼。我需要閱讀文件到xsd__base64Binary,所以我可以分配到remoteFile.FileByteStream
BasicHttpBinding_USCOREITransferService svc;
__ns1__UploadFileResponse uploadRespond;
_ns1__RemoteFileInfo remoteFile;
std::string path = "C:\\temp\\upload\\test.txt";
我需要閱讀上述文件到 ????
remoteFile.FileByteStream = ?
這樣我就可以調用webservice的uploadFile如下:
int result = svc.__ns1__UploadFile(&remoteFile, uploadRespond);
謝謝你在前進,
JH
我試圖做同樣的....我實現與MTOM附件的SOAP客戶端...和...它是如何添加的配置參數?像這樣: 'Content-Type:application/zip Content-Transfer-Encoding:binary Content-ID: Content-Disposition:attachment; NAME = 「example.zip」' –