简体   繁体   English

使用Java消费.net Web服务未显示预期结果

[英]Consuming a .net web service with java not showing expected results

I'm having problems to consume a .NET Web Service from a simple Java Application. 我在从简单的Java应用程序使用.NET Web服务时遇到问题。 I'm only testing right now if the web service client fetches the expected data, and apparently it doesn't. 我现在只是在测试Web服务客户端是否获取了预期的数据,显然不是。 I created a Web Service Client in Eclipse using the wsdl location and it went right. 我使用wsdl位置在Eclipse中创建了一个Web Service Client,它运行正确。 Also, I've tested the methods in the .NET side and they are working alright. 另外,我已经在.NET方面测试了这些方法,并且它们都可以正常工作。 So the problem must be something I'm missing when using the methods generated by the Web Service Client. 因此,当使用Web Service Client生成的方法时,问题一定是我所缺少的。 I'll show the code which is almost ridiculy simple: 我将展示几乎非常简单的代码:

package com.consumeserviciodirectorio;
import java.rmi.RemoteException;
import org.apache.axis.AxisFault;
import org.tempuri.*;
import org.datacontract.schemas._2004._07.DAL_DirectorioCide_Modelo.*;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
try {

IDirectorioCIDEProxy d = new IDirectorioCIDEProxy();
String resp = d.jerry("ya");
System.out.println(resp);
ModeloEmpleadoParaDirectorio[] lista = d.consulta("Paterno=|osorio|");
System.out.println(lista.length);
for(ModeloEmpleadoParaDirectorio res:lista){
System.out.println("Nombre: "+res.getNombres()+" Apellidos: "+res.getPaterno()+" "+res.getMaterno());
System.out.println("Area: "+res.getAreaDescripcion()+" Email: "+res.getEmailCia());
}
}
catch (AxisFault e) {
    System.out.println(e.getMessage()+ " "+e.getFaultReason());
}
catch (RemoteException ex) {
    System.out.println(ex.getMessage());
}
    }

}

Also, the code in the .NET end is like so (it's tested and it works with the parameter as I'm passing it above): 另外,.NET端的代码是这样的(它已经过测试,并且在我通过上面的参数时可以与参数一起使用):

public List<Modelo.ModeloEmpleadoParaDirectorio> Consulta(string Consulta)
        {
            List<Modelo.ModeloEmpleadoParaDirectorio> _result = new List<Modelo.ModeloEmpleadoParaDirectorio>();
            try
            {
                using (EvolutionCatalogosEntities modelo = new EvolutionCatalogosEntities())
                {
                    Consulta = Consulta.Replace("|", "\"");
                    _result = (from U in modelo.Empleado
                               join C in modelo.CatAreas on U.ActInstId equals C.IdCatArea
                               select new Modelo.ModeloEmpleadoParaDirectorio
                               {
                                   Id = U.Id,
                                   Nombres = U.Nombres,
                                   Paterno = U.Paterno,
                                   Materno = U.Materno,
                                   AreaDescripcion = C.AreaDescripcion,
                                   EmailCia = U.EmailCia
                               }).AsQueryable().Where(Consulta).ToList();
                }
                return _result;
            }
            catch
            {
                return _result;
            }
        }

However the variable called lista is an empty array no matter what I do, meaning that it's length is 0. There must be something I'm missing but I've used the same method to call the web service before and it worked. 但是,无论执行什么操作,称为lista的变量都是一个空数组,这意味着它的长度为0。一定缺少我想要的东西,但是我之前使用相同的方法来调用Web服务,并且它起作用了。 Can someone point out what's the problem with that code? 有人可以指出该代码有什么问题吗?

I found the answer debugging the service on the .NET end. 我找到了在.NET端调试服务的答案。 The problem was there was a missing connection string of the model in the web.config of the svc. 问题是svc的web.config中缺少模型的连接字符串。 I knew the code wasn't a problem, on any of the points connecting. 从连接的任何方面来看,我都知道代码不是问题。 Sorry for posting a question that was probably not related to the actual problem. 抱歉,发布的问题可能与实际问题无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM