2013-12-21 139 views
0

我有一个Web服务查询数据库并返回这些查询的结果。 但是,web服务不能直接访问数据库,而是使用用户创建的库来查询它,并使用特定的方法来检索用户,名称等。 我已将该库包含在webservice项目中,方法是选择add>参考,我没有得到我的web服务代码编译错误或警告。 我已经使用svcutil.exe和wsutil.exe创建了客户端库,并且一切正常,没有任何警告。 在我的客户端代码中,我收到了“处理tempuri.org.xsd时出错”,“为DataSet生成代码时出错”,“无法将输入xml文件转换为DataSet”嵌套表'Utilizador'继承相应的名称空间不能在不同的名称空间中有多个表“。 最后一个错误被翻译成葡萄牙语,我尽我所能将它翻译回英文,所以YMMV ...'Utilizador'是我的DB上的表名和访问数据库的类上的类名。 我使用这个代码来使用WebService的:使用C++客户端消费.NET WebService

#include "stdafx.h" 
#include "WebServices.h" 
#include "schemas.microsoft.com.2003.10.Serialization.xsd.h" 
#include "tempuri.org.xsd.h" 
#include "tempuri.org.wsdl.h" 
#include <string> 
#include <iostream> 
#include <stdlib.h> 

using namespace std; 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    unsigned int *listSize; 
    Utilizador **arrayUser; 
    HRESULT hr = ERROR_SUCCESS; 
    WS_ERROR* error = NULL; 
    WS_HEAP* heap = NULL; 
    WS_SERVICE_PROXY* proxy = NULL; 
    WS_ENDPOINT_ADDRESS address = {}; 
    WS_STRING url= WS_STRING_VALUE(L"http://localhost:51765/Graph4Social.svc"); 
    address.url = url; 
    hr = WsCreateHeap(2048, 512, NULL, 0, &heap, error); 
    WS_HTTP_BINDING_TEMPLATE templ = {}; 
    //criação do proxy para o serviço 
    //hr = BasicHttpBinding_IGraph4WebService_CreateServiceProxy(&templ, NULL, 0, &proxy, error); 
    //WsCreateServiceProxy(&templ, NULL, 0, &proxy, error); 
    hr = BasicHttpBinding_IGraph4Social_CreateServiceProxy(&templ, NULL, 0, &proxy, error); 
    hr = WsCreateServiceProxy(WS_CHANNEL_TYPE_REQUEST,WS_HTTP_CHANNEL_BINDING,NULL,NULL,0,NULL,0,&proxy,error); 
    hr = WsOpenServiceProxy(proxy,&address,NULL,error); 

    hr = BasicHttpBinding_IGraph4Social_getUserList(proxy,listSize,&arrayUser,heap, NULL,0, NULL,error); 

    for (unsigned int i = 0; i < *listSize; i++) 
     cout << "ID Utilizador: " + arrayUser[i]->idUtilizador; 
    return 0; 
} 

这是接口WebService的代码:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 
using TM_TDG.WithDataSets.BLL; 
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IGraph4Social" in both code and config file together. 
[ServiceContract] 
public interface IGraph4Social 
{ 
    [OperationContract] 
    IList<Utilizador> getUserList(); 
} 

这是实现接口的类的代码:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.Text; 
using TM_TDG.WithDataSets.BLL; 
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Graph4Social" in code, svc and config file together. 
public class Graph4Social : IGraph4Social 
{ 
    public IList<Utilizador> getUserList() 
    { 
     RedeSocial rede = RedeSocial.getRedeSocial(); 
     IList<Utilizador> userList = rede.getUserList(true); //so queremos os utilizadores activos 
     return userList; 
    } 
} 

我GOOGLE了这个错误,似乎无法找到答案。我希望有人能帮助我,因为我在这个问题上一直坚持了几天!

谢谢!

回答

0

我真的只是偶然的解决了这个昨晚!事实证明,我将项目页面上的svcutil.exe和wsutil.exe生成的所有文件(包括由svcutil.exe生成的.xsd和.wsdl)。我还将所有项目添加到Visual Studio项目中,但显然,我只包含.h文件。我认为编译器只会查看.h和相应的.c文件,但事实证明,它也在查看.xsd和.wsdl。当我删除这些文件时,编译器完美无缺地工作! 所以,PEBKAC ... 不知道,如果这是与Visual Studio相关的,或者如果这种行为可以用gC++来重现,例如。